package com.example.shoppingmall.cotroller;

import com.example.shoppingmall.Utils.Page;
import com.example.shoppingmall.config.MyLog;
import com.example.shoppingmall.pojo.SysLog;
import com.example.shoppingmall.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/log")
public class SysLogController {
    @Autowired
    SysLogService sysLogService;

    String utimes=null;

    @MyLog(value = "控制面板->查看日志")
    @RequestMapping("/loglist")
    public String loglist(@RequestParam(value = "pageno",defaultValue = "1") Integer pageno,
                          @RequestParam(value = "pageSize",defaultValue = "6") Integer pageSize,
                          Model model,@RequestParam(value = "utime",required = false) String utime){
        if(utime!=null){
            utimes=utime;
        }
        int count=sysLogService.logcount(utimes);
        int num=(Integer.valueOf(pageno)-1)*Integer.valueOf(pageSize);
        Page page=new Page();
        page.setPageno(Integer.valueOf(pageno));
        page.setPageCount(count);
        List<SysLog> logList=sysLogService.getLogAll(utimes,num,Integer.valueOf(pageSize));
        model.addAttribute("page",page);
        model.addAttribute("logList",logList);
        model.addAttribute("utime",utime);
        return "log/Log";
    }
}
